<?xml version="1.0"?>
<jsp:root 	xmlns:jsp="http://java.sun.com/JSP/Page"
			xmlns:sql="http://java.sun.com/jsp/jstl/sql"
			xmlns:c="http://java.sun.com/jsp/jstl/core" 
			xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
			version="2.1">
	<jsp:directive.page contentType="text/html; charset=UTF-8" />
	<jsp:directive.page isELIgnored="false" />
	<jsp:output omit-xml-declaration="false"
		doctype-root-element="html"
		doctype-public="-//W3C//DTD XHTML 1.1//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd" /> 
		
	<!-- Carrito  -->
	<jsp:useBean id="userBean" class="es.albarregas.beans.UserBean" scope="session" />
	<jsp:useBean id="listaPedidosBean" class="es.albarregas.beans.PedidoListBean" scope="session" />
	
	<jsp:setProperty property="clausulaWhere" name="listaPedidosBean" value="where user_oid=${userBean.oid} and confirmado=false" />
	  
	<c:if test="${userBean.oid != 0}">
		<c:set var="clausula" 	value=" where user_oid=${userBean.oid} and confirmado=false" />
		<jsp:setProperty property="clausulaWhere" name="listaPedidosBean" value="${clausula}" />
		<c:set var="oidPedido" value="0" />
		<c:set var="totalPedido" value="0"></c:set>
		<c:forEach var="registros" items="${listaPedidosBean.pedido}">
			<c:set var="oidPedido" value="${registros.oid}" />
			<c:set var="totalPedido" value="${registros.total }"></c:set>
			<c:set var="elPedido" value="${registros}" scope="session"></c:set>
		</c:forEach>
		<c:if test="${oidPedido != 0}">
			<jsp:useBean id="listaLineasPedidoBean" class="es.albarregas.beans.LineasPedidoListBean" scope="session" />
			<c:set var="clausula2" value="where pedido_oid=${oidPedido}" />	
			<jsp:setProperty property="clausulaWhere" name="listaLineasPedidoBean" value="${clausula2}" />
		</c:if>		
    </c:if>

	<c:set var="nProductos" value="0"></c:set>
	<c:if test="${listaPedidosBean.pedido.size() != 0}">
		<c:set var="nProductos" value="${listaLineasPedidoBean.lineaPedido.size()}"></c:set>
	</c:if>
 			<!--  ===========  -->
            <!--  = Carrito =  -->
            <!--  ===========  -->
            <div class="span3">
                <div class="cart-container" id="cartContainer">
                    <div class="cart">
                        <p class="items">Carrito <span class="dark-clr">(<c:out value="${nProductos}" />)</span></p>
                        <p class="dark-clr hidden-tablet"><fmt:formatNumber type="currency" currencySymbol="€" value="${totalPedido}" minFractionDigits="2"/></p>
                        <a href="checkout-paso-1.jsp" class="btn btn-danger">
                            <!-- <span class="icon icons-cart"></span> -->
                            <span class="icon-shopping-cart"></span>
                        </a>
                    </div>
                    <div class="open-panel">
                         <c:choose>
                         	<c:when test="${listaPedidosBean.pedido.size() != 0}">
	                        	<c:forEach var="itemCarrito" items="${listaLineasPedidoBean.lineaPedido }">
		                         	<div class="item-in-cart clearfix">
			                            <div class="image">
			                                <img src="${itemCarrito.thumbproducto }" width="124" height="124" alt="cart item" />
			                            </div>
			                            <div class="desc">
			                                <strong><a href="product.html">${itemCarrito.nombreProducto }</a></strong>
			                                <span class="light-clr qty">
			                                    Cantidad: <c:out value="${itemCarrito.cantidad }"></c:out>
			                                    &#160;
			                                    <c:url var="urlDelete" value="/delete-line">
													<c:param name="oidLinea" value="${itemCarrito.oid}"></c:param>
												</c:url>
			                                    <a href="${urlDelete }" title="Eliminar Item"><span class="icon-remove-sign"></span></a>
			                                </span>
			                            </div>
			                            <div class="price">
			                                <strong><fmt:formatNumber type="currency" currencySymbol="€" value="${itemCarrito.precioUnitario}" /></strong>
			                            </div>
		                        </div>                         
	                     	</c:forEach>
                 
                         
                         
                        <div class="summary">
                            <div class="line">
                                <div class="row-fluid">
                                    <div class="span6">Envío:</div>
                                    <div class="span6 align-right"><fmt:formatNumber type="currency" currencySymbol="€" value="${elPedido.gastosEnvio}"/></div>
                                </div>
                            </div>
                            <div class="line">
                                <div class="row-fluid">
                                    <div class="span6">Total:</div>
                                    <div class="span6 align-right size-16"><fmt:formatNumber type="currency" currencySymbol="€" value="${elPedido.total + elPedido.gastosEnvio}" minFractionDigits="2"/></div>
                                </div>
                            </div>
                        </div>
                        <div class="proceed">
                            <a href="checkout-paso-1.jsp" class="btn btn-danger pull-right bold higher">FINALIZAR <span class="icon-shopping-cart"></span></a>
                            <small>Los costes de envío están calculados en base a la localización. <a href="#">Más información</a></small>
                        </div>
                                </c:when>
                         <c:otherwise>
                         	<p class="empty">No hay productos en el carrito.</p>
                         </c:otherwise>
                         </c:choose>
                    </div>
                </div>
            </div> <!-- /cart -->
            
            </jsp:root>